package com.sunwayworld.basemodule.common.eptstorage.db.resource.impl;

import com.sunwayworld.basemodule.common.eptstorage.db.bean.LimsDbconnBean;
import com.sunwayworld.framework.data.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sunwayworld.basemodule.common.eptstorage.db.resource.LimsDbconnResource;
import com.sunwayworld.basemodule.common.eptstorage.db.service.LimsDbconnService;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import com.sunwayworld.framework.log.annotation.Log;
import com.sunwayworld.framework.log.annotation.LogModule;
import com.sunwayworld.framework.log.annotation.LogType;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;

import java.util.List;
import java.util.Map;

@LogModule("数据库链接配置")
@RestController
@GikamBean
public class LimsDbconnResourceImpl implements LimsDbconnResource {

    @Autowired
    private LimsDbconnService limsDbconnService;

    @Override
    public LimsDbconnService getService() {
        return limsDbconnService;
    }

    @Log(value = "新增数据库链接配置", type = LogType.INSERT)
    @Override
    @RequestMapping(method = RequestMethod.POST)
    public Long insert(RestJsonWrapperBean wrapper) {
        return getService().insert(wrapper);
    }

    @Override
    public Page<LimsDbconnBean> selectUiPagination(RestJsonWrapperBean wrapper) {
        Page<LimsDbconnBean> pagination = this.getService().selectPagination(wrapper);
        for (LimsDbconnBean row : pagination.getRows()) {
            row.setPassword(null);
        }
        return pagination;
    }

    @Override
    public String connect(RestJsonWrapperBean wrapper) {
        return getService().connect(wrapper);
    }

    @Override
    public List<Map<String, Object>> testSQL(RestJsonWrapperBean wrapper) {
        return getService().testSQL(wrapper);
    }
}
